﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DBUtil;

namespace DAL
{
    public class Data_BindDateDAL
    {
        #region --绑定数据，返回object
        /// <summary>
        /// 绑定数据，返回object
        /// </summary>       
        /// <param name="Message">返回错误异常</param>
        /// <param name="tablename">表的名称</param>       
        /// <param name="strOrder">排序列名称</param>  
        /// <param name="intOrder">排序方式，0：升序（默认） 1：降序</param>       
        /// <param name="TopCount">可显示的记录数，0：无限</param>        
        /// <returns>返回object</returns>		
        public static DataTable Page_BindDate(out string Message, string tablename, string strOrder, int intOrder, int TopCount, string connection)
        {
            Message = "";
            DataTable Val = null;
            try
            {
                SqlParameter[] sqlparams = {
                new SqlParameter("@tblName",SqlDbType.VarChar,1000), 
                new SqlParameter("@fldSort",SqlDbType.VarChar,1000),
                new SqlParameter("@Sort",SqlDbType.Bit),
                new SqlParameter("@TopCount",SqlDbType.Int)
                };
                sqlparams[0].Value = tablename.Trim();
                sqlparams[1].Value = strOrder.Trim();
                sqlparams[2].Value = intOrder;
                sqlparams[3].Value = TopCount;

                Val = new DbHelperSQLP(connection).RunProcedure("Sys_Page_BindDataSet", sqlparams, "table").Tables[0];
            }
            catch (ArgumentException e)
            {
                Message = e.Message;
            }
            return Val;
        }
        #endregion

        #region --绑定数据，返回object
        /// <summary>
        /// 绑定数据，返回object
        /// </summary>       
        /// <param name="Message">返回错误异常</param>
        /// <param name="tablename">表的名称</param>       
        /// <param name="strOrder">排序列名称</param>  
        /// <param name="intOrder">排序方式，0：升序（默认） 1：降序</param>
        /// <param name="TopCount">可显示的记录数，0：无限</param>        
        /// <param name="strWhere">需要查询的条件,前面不加where</param>
        /// <returns>返回object</returns>		
        public static DataTable Page_BindDate(out string Message, string tablename, string strOrder, int intOrder, int TopCount, string strWhere, string connection)
        {
            Message = "";
            DataTable Val = null;
            try
            {
                SqlParameter[] sqlparams = {
                new SqlParameter("@tblName",SqlDbType.VarChar,1000), 
                new SqlParameter("@fldSort",SqlDbType.VarChar,1000),
                new SqlParameter("@Sort",SqlDbType.Bit),
                new SqlParameter("@TopCount",SqlDbType.Int),
                new SqlParameter("@strCondition",SqlDbType.VarChar,1000)
                };
                sqlparams[0].Value = tablename.Trim();
                sqlparams[1].Value = strOrder.Trim();
                sqlparams[2].Value = intOrder;
                sqlparams[3].Value = TopCount;
                sqlparams[4].Value = strWhere;

                //DAL.Sql_BaseDAL MySqlBase = new DAL.Sql_BaseDAL();
                //MySqlBase.myParameter = sqlparams;
                //MySqlBase.SqlConnectionString = _connection;
                //Val = MySqlBase.SqlProcedure_DataTable(out Message, "Sys_Page_BindDataSet", true);

                Val = new DbHelperSQLP(connection).RunProcedure("Sys_Page_BindDataSet", sqlparams, "table").Tables[0];
            }
            catch (ArgumentException e)
            {
                Message = e.Message;
            }
            return Val;
        }
        #endregion
    }
}
